/* 
 * File:   HamiForm.h
 * Author: nzhao
 *
 * Created on September 7, 2010, 10:46 AM
 */

#ifndef _HAMIFORM_H
#define	_HAMIFORM_H

#include "share/Usrdef.h"
#include "core/globalvars.h"
#include "share/parameters.h"
#include "share/GenClst_Algorithm.h"
#include "share/GenClst_Control.h"

#define ZERO_ARRAY 0
#define BX_ARRAY 1
#define BY_ARRAY 2
#define BZ_ARRAY 3

#define XX_ARRAY 4
#define YY_ARRAY 5
#define ZZ_ARRAY 6
#define XY_ARRAY 7
#define YZ_ARRAY 8
#define ZX_ARRAY 9
#define YX_ARRAY 10
#define ZY_ARRAY 11
#define XZ_ARRAY 12

#define MAX_SPECIES 10	// spin 1/2 ~ spin 5
#define MAX_HAMI_FORM 100

struct HamiElement
{
    int nterms_R;
    int nterms_I;
    int * termName_R;
    int * termName_I;
    double * coefflist_R;
    double * coefflist_I;
    int    * idxlist_R;
    int    * idxlist_I;
};

struct basis
{
    int nspin;
    int nExcite;
    int * state;
};

class clusterHamiltonian
{
public:
    int CreateHamiForm(int nspin, int * sgl_dim, int isBLK);
    int BlockNumer(){return(nBlock);};
    int * HamiDim(){return(dim);};
    int FullDim(){return(full_dim);};
    double ElementVal_R(double ** interaction, int blk, int idx);
    double ElementVal_I(double ** interaction, int blk, int idx);

private:
    int initialize(int nspin, int * sgl_dim, int isBLK);
    void idx2excitenum(int i, int * exciteN_list);
    int createHami(int n_start, int n_end, HamiElement * mat);
    int mat_elements(HamiElement&  ele, basis state_i, basis state_j);
    int mat_element_diagonal(HamiElement&  ele, basis state_i);
    int mat_element_off_diagonal1(HamiElement&  ele, basis state_i, basis state_j, int * diff_site);
    int mat_element_off_diagonal2(HamiElement&  ele, basis state_i, basis state_j, int * diff_site);

    int full_dim;
    int * accDim;
    int spin_num;
    int isBlock;
    int nBlock;
    int * dim_start, * dim_end, * dim;

    double * S_Val;
    HamiElement ** matList;

    basis * basisList;
};

extern int 	** HAMI_FORM_LIST;
extern int	HAMI_FORM_LEN;
extern int	** CLUSTER_2_HamiFORM;
extern clusterHamiltonian * hm;
void 	generate_hamiltonian_forms();

#endif	/* _HAMIFORM_H */

